package org.dromara.bus.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.bus.domain.vo.YxdStashVo;
import org.dromara.bus.domain.bo.YxdStashBo;
import org.dromara.bus.service.IYxdStashService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 熠星达仓库
 *
 * @author csy
 * @date 2024-03-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/bus/stash")
public class YxdStashController extends BaseController {

    private final IYxdStashService yxdStashService;

    /**
     * 查询熠星达仓库列表
     */
    @SaCheckPermission("bus:stash:list")
    @GetMapping("/list")
    public TableDataInfo<YxdStashVo> list(YxdStashBo bo, PageQuery pageQuery) {
        return yxdStashService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出熠星达仓库列表
     */
    @SaCheckPermission("bus:stash:export")
    @Log(title = "熠星达仓库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(YxdStashBo bo, HttpServletResponse response) {
        List<YxdStashVo> list = yxdStashService.queryList(bo);
        ExcelUtil.exportExcel(list, "熠星达仓库", YxdStashVo.class, response);
    }

    /**
     * 获取熠星达仓库详细信息
     *
     * @param stashId 主键
     */
    @SaCheckPermission("bus:stash:query")
    @GetMapping("/{stashId}")
    public R<YxdStashVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long stashId) {
        return R.ok(yxdStashService.queryById(stashId));
    }

    /**
     * 新增熠星达仓库
     */
    @SaCheckPermission("bus:stash:add")
    @Log(title = "熠星达仓库", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody YxdStashBo bo) {
        return toAjax(yxdStashService.insertByBo(bo));
    }

    /**
     * 修改熠星达仓库
     */
    @SaCheckPermission("bus:stash:edit")
    @Log(title = "熠星达仓库", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody YxdStashBo bo) {
        return toAjax(yxdStashService.updateByBo(bo));
    }

    /**
     * 删除熠星达仓库
     *
     * @param stashIds 主键串
     */
    @SaCheckPermission("bus:stash:remove")
    @Log(title = "熠星达仓库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{stashIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] stashIds) {
        return toAjax(yxdStashService.deleteWithValidByIds(List.of(stashIds), true));
    }
}
